<template>
  <div>
    <div v-show="!isDetail" class="page-index">
      <div>
        <div class="table-search">
          <el-form inline>
            <el-form-item label="标题名称">
              <el-input v-model="queryParams.titleHelpWork" size="mini" placeholder="请输入" />
            </el-form-item>
            <el-form-item label="发起人">
              <el-input v-model="queryParams.sponsorName" size="mini" placeholder="请输入" />
            </el-form-item>
            <el-form-item label="交办人">
              <el-input v-model="queryParams.assignDelegateName" size="mini" placeholder="请输入" />
            </el-form-item>
            <el-form-item label="发起时间">
              <el-date-picker
                v-model="initiationTime"
                size="mini"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                value-format="yyyy-MM-dd"
                @change="timeChange"
              />
            </el-form-item>
            <el-form-item label="认领状态">
              <el-select v-model="queryParams.claimStatus" size="mini" placeholder="请选择" >
                <el-option label="已认领" value="1" />
                <el-option label="未认领" value="0" />
              </el-select>
            </el-form-item>
            <el-form-item label="是否办结">
              <el-select v-model="queryParams.doneOrNot" size="mini" placeholder="请选择" >
                <el-option label="已办结" value="1" />
                <el-option label="未办结" value="0" />
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-button size="mini" type="primary" @click="search">搜索</el-button>
              <el-button size="mini" @click="reset">重置</el-button>
            </el-form-item>
          </el-form>
          <el-form inline>
            <el-form-item>
              <el-button size="mini" type="primary" @click="openAdd">新增</el-button>
            </el-form-item>
          </el-form>
        </div>
        <div class="table-box">
          <el-table
            :data="tableData"
            height="100%"
          >
            <el-table-column type="index" label="序号" align="center" width="50" />
            <el-table-column prop="titleHelpWork" label="帮扶工作标题" align="center" min-width="180" />
            <el-table-column prop="helpingWorkPlace" label="帮扶地点" align="center" min-width="240" />
            <el-table-column prop="sponsorName" label="发起人" align="center" width="120" />
            <el-table-column prop="assignDelegateName" label="交办人" align="center" width="120" />
            <el-table-column prop="claimStatus" label="任务认领状态" align="center" width="150">
              <template slot-scope="scope">
                {{ scope.row.claimStatus==='0'?'未认领':'已认领' }}
              </template>
            </el-table-column>
            <el-table-column prop="initiationTime" label="发起时间" align="center" width="160" />
            <el-table-column prop="doneOrNot" label="是否办结" align="center" width="120">
              <template slot-scope="scope">
                {{ scope.row.doneOrNot==='0'?'否':'是' }}
              </template>
            </el-table-column>
            <el-table-column prop="completeHelpingWorkTime" label="办结时间" align="center" width="160" />
            <el-table-column label="操作" align="center" width="160">
              <template slot-scope="scope">
                <el-button
                  type="text"
                  size="mini"
                  @click="openDetail(scope.row)"
                >详情</el-button>
                <el-button
                  type="text"
                  size="mini"
                  @click="openEdit(scope.row)"
                >编辑</el-button>
                <el-button
                  type="text"
                  size="mini"
                  @click="openDetail(scope.row,true)"
                >办理</el-button>
                <el-button
                  type="text"
                  size="mini"
                  style="color:#F56C6C;"
                  @click="openDelete(scope.row)"
                >删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <pagination
          :total="total"
          :page.sync="queryParams.pageNo"
          :limit.sync="queryParams.pageSize"
          @pagination="getData"
        />
      </div>
      <addOrEdit ref="addOrEdit" @getData="getData" />
    </div>
    <detailPage v-show="isDetail" ref="detailPage" @goback="detailGoback" />
  </div>
</template>
<script>
import { queryByCondition, queryById, deleteById } from '@/api/cadreBusiness/massAssistance'
import addOrEdit from './components/addOrEdit'
import detailPage from './components/detail'
export default {
  components: {
    addOrEdit,
    detailPage
  },
  data () {
    return {
      queryParams: {
        pageNo: 1,
        pageSize: 10
      },
      total: 0,
      tableData: [],
      initiationTime: [],
      isDetail: false
    }
  },
  mounted () {
    this.getData()
  },
  methods: {
    getData () {
      queryByCondition(this.queryParams).then((res) => {
        this.tableData = res?.data?.records || []
        this.total = res?.data?.total || 0
      })
    },
    search () {
      this.queryParams.pageNo = 1
      this.getData()
    },
    openAdd () {
      this.$refs.addOrEdit.open({})
    },
    openEdit (row) {
      queryById({ id: row.id }).then((res) => {
        this.$refs.addOrEdit.open(res?.data || row)
      })
    },
    openDelete (row) {
      this.$confirm('是否确认删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteById({ id: row.id }).then((res) => {
          this.$message.success('删除成功')
          this.getData()
        })
      })
    },
    openDetail (row) {
      queryById({ id: row.id }).then((res) => {
        this.isDetail = true
        this.$refs.detailPage.init(res.data || row)
      })
    },
    detailGoback (isQuery) {
      this.isDetail = false
      if (isQuery) {
        this.getData()
      }
    },
    reset () {
      this.search()
    }
  }
}
</script>
<style scoped lang="scss">
.page-index {
  padding-top: 24px;
  .table-search {
    // display: flex;
    // justify-content: space-between;
    padding-left:16px;
  }
  .table-box {
    height: calc(100vh - 330px);
  }
}

</style>
